package com.qst.pojo.vo;

import com.qst.pojo.entity.StationInventory;
import lombok.Data;

import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * 站点库存视图对象
 */
@Data
public class StationInventoryVO {
    private Integer id;
    private Integer stationId;
    private Integer itemId;
    private String itemName;
    private String category;
    private String unit;
    private BigDecimal quantity;
    private BigDecimal minStock = BigDecimal.valueOf(10);  // 最低库存，默认10
    private BigDecimal maxStock = BigDecimal.valueOf(100); // 最高库存，默认100
    private BigDecimal averagePrice;  // 平均单价
    private LocalDateTime lastUpdated;
    
    /**
     * 从StationInventory实体转换为VO
     */
    public static StationInventoryVO fromEntity(StationInventory inventory) {
        StationInventoryVO vo = new StationInventoryVO();
        vo.setId(inventory.getId());
        vo.setStationId(inventory.getStationId());
        vo.setItemId(inventory.getItemId());
        vo.setQuantity(inventory.getQuantity());
        vo.setMinStock(inventory.getMinStock() != null ? inventory.getMinStock() : BigDecimal.valueOf(10));
        vo.setMaxStock(inventory.getMaxStock() != null ? inventory.getMaxStock() : BigDecimal.valueOf(100));
        vo.setLastUpdated(inventory.getLastUpdated());
        
        // 设置物品信息
        if (inventory.getItem() != null) {
            vo.setItemName(inventory.getItem().getName());
            vo.setCategory(inventory.getItem().getCategory());
            vo.setUnit(inventory.getItem().getUnit());
            vo.setAveragePrice(inventory.getItem().getPricePerUnit());
        }
        
        return vo;
    }
}
